namespace SimpleWebServices.Web.Routing
{
    using System;
    using System.Web.Mvc;
    using System.Web.Routing;

    public static class RouteCollectionTestingExtensionMethods
    {
        public static bool Contains<T>(this RouteCollection routes, string path)
            where T : ControllerBase
        {
            if (null == routes)
            {
                throw new ArgumentNullException("routes");
            }
            else if (null == path)
            {
                throw new ArgumentNullException("path");
            }
            else if (0 == path.Length)
            {
                throw new ArgumentOutOfRangeException("path");
            }

            bool result = false;

            foreach (Route route in routes)
            {
                if (route.Url.Equals(path, StringComparison.OrdinalIgnoreCase)
                    && route.RouteHandler is GenericRouteHandler<T>)
                {
                    result = true;
                    break;
                }
            }

            return result;
        }
    }
}